<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout ref="projDetailLayout" :process-instance-id="processInstanceId" :project-number="projectNumber">
    <d-forms label-width="200rpx">
      <d-forms-item label="采购用途" :input="form.projectName || form.projectNumber"></d-forms-item>
      <d-forms-item label="通用属性模块类别" :type="DFormInputType.DICT" :dict-type="PM_DICT_TYPE.GENERAL_ATTR_CATEGORY" :input="form.generalAttrCategory"></d-forms-item>
      <d-forms-item label="备件类别" :type="DFormInputType.DICT" :dict-type="PM_DICT_TYPE.SPARE_TYPE" :input="form.category"></d-forms-item>
      <d-forms-item label="库存数量" :input="form.allowNum || form.applyQuota" :suffix="form.unit"></d-forms-item>
      <d-forms-item label="价值" :input="form.worth"></d-forms-item>
      <d-forms-item label="备件归属地" :type="DFormInputType.DICT" :dict-type="PM_DICT_TYPE.SPARE_BELONG_PLACE" :input="form.belongPlace"></d-forms-item>
      <d-forms-item label="品牌/厂商">
        <pm-supplier-select disabled :firm-id="form.firm"></pm-supplier-select>
      </d-forms-item>
      <d-forms-item label="参数规格" :input="form.specifications"></d-forms-item>
      <d-forms-item label="申请数量" :input="form.applyNum" :suffix="form.unit"></d-forms-item>
      <d-forms-item label="申请人">
        <pm-user-select disabled :user-id="form.applicant"></pm-user-select>
      </d-forms-item>
      <d-forms-item label="申请时间" :type="DFormInputType.DATE" :input="form.applyTime"></d-forms-item>
      <view>
        <view class="form-title-1">申请事由</view>
        <d-card>
          <d-forms-item disabled :input="form.reason"></d-forms-item>
        </d-card>
      </view>
      <view>
        <view class="form-title-1">附件</view>
        <d-card>
          <pm-file-upload readonly :files="form.attach"></pm-file-upload>
        </d-card>
      </view>
    </d-forms>
  </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">
import {usePmSpareWareApi} from "@/api/pm/resource/spareWare";
import ProjDetailLayout from "@/components/ProjDetailLayout/index.vue";
import {PM_DICT_TYPE} from "@/utils/pmDict";
import {DFormInputType} from "@/utils/enum";

defineOptions({ name: 'SpareWareUseApply' })

const initForm = {
  traceId: null,
  spareWarehouseId: null,
  applyNum: null,
  applyTime: null,
  reason: null,
  attach: null,
  id: null,
  projectNumber: null,
  projectName: null,
  category: null,
  generalAttrCategory: null,
  unit: null,
  worth: null,
  belongPlace: null,
  firm: null,
  specifications: null,
  allowNum: null,
  applyQuota: null,
  applicant: null,
  processInstanceId: null,
  result: null,
}
const form = ref<SpareWareUseForm>(initForm)
const triggered = ref<boolean>(false);
function getDetail() {
  if (processInstanceId.value) {
    triggered.value = true;
    usePmSpareWareApi().getSWUserApplyByPiId(processInstanceId.value).then(res => {
      if (res.code === 0) {
        form.value = res.data || initForm
      }
    }).finally(() => {
      triggered.value = false;
    })
  }
}

const projectNumber = ref<string>(null);
const processInstanceId = ref<string>(null);
onLoad((query) => {
  projectNumber.value = query['project_number']
  processInstanceId.value = query['process_instance_id']
  getDetail();
})
</script>

<style scoped lang="scss">

</style>
